<#-- @ftlvariable name="containerTable" type="com.fable.sp.core.domain.ContainerTable" -->

package com.fable.smart.page.model;

import com.fable.sp.core.util.JSONType;
import com.fable.sp.core.util.SnowflakeGenerator;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import org.springframework.data.jpa.domain.AbstractPersistable;

@Entity
@Table(name="${containerTable.tableName}")
public class ${containerTable.genClassName()} implements Serializable{
    @Id
    @GenericGenerator(name = "snowflake", strategy = SnowflakeGenerator.TYPE)
    @GeneratedValue(generator = "snowflake")
    private Long id;

    public void setId(Long id){
        this.id = id;
    }

    public Long getId(){
        return id;
    }

    <#assign columnDefs = containerTable.instanceColumns?values/>
    <#list columnDefs as cdf>
        <#assign columName = "col_"+cdf.name/>
        <#assign columType='long' />
        <#switch cdf.columnType>
            <#case "BOOLEAN">
                <#assign columType='Boolean'/>
                <#break>
            <#case "STRING">
                <#assign columType='String'/>
                <#break>
            <#case "NUMBER">
                <#if cdf.length gte 8>
                    <#assign columType='Long'/>
                <#else >
                    <#assign columType='Int'/>
                </#if>
                <#break>
            <#default>
                <#assign columType='String'/>
        </#switch>
        <#if cdf.columnType == "LOB" || (cdf.columnType == "STRING" && cdf.length>2000)>
            @Column(name="${columName}",length = 100000)
            @Lob
            <#elseif cdf.columnType == "BOOLEAN">@Column(name="${columName}")
            <#else >@Column(name="${columName}",length=${cdf.length})
        </#if>
        private ${columType} ${columName};

        public void set${columName?cap_first}(${columType} v){
            this.${columName} = v;
        }

        public ${columType} get${columName?cap_first}(){
            return this.${columName};
        }
    </#list>
    }